/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sd.rmi.auction.client;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;
import sd.rmi.auction.interfaces.IAuction;

/**
 *
 * @author blackdevil
 */
public class ClientProxy implements IAuction{

    final static String serverUrlLocale = "127.0.0.1";
    final static String serverUrlExt = "";
    final static String serverUrlLan = "";
    private IAuction stub = null;
    private String serviceName = null;

    public ClientProxy(String serviceName) {
        
        this.serviceName = serviceName;
        try {
            System.out.println("Locate registry");
            Registry registry = LocateRegistry.getRegistry(serverUrlLocale);
            System.out.println("Service lookup");
            this.stub = (IAuction) registry.lookup(serviceName);
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
   

    @Override
    public void setBid(int bid)
    {
        try{
            stub.setBid(bid);        
        } catch (RemoteException ex) {
            Logger.getLogger(ClientProxy.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
    }

    @Override
    public int getCurrentBid()
    {
        try {
            return stub.getCurrentBid();
        } catch (RemoteException ex) {
            Logger.getLogger(ClientProxy.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
            return 0;
        }
    }

    @Override
    public String getProduct()
    {
        try {
           return  stub.getProduct();
        } catch (RemoteException ex) {
            Logger.getLogger(ClientProxy.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
            return "";
        }
    }
}
